import Foundation
import ULID
import ObjectBox

class ysRDndYhHqiivjct: ylSrwpQzinRnCQAz {
    static let WwJoBsxnOnzHObMj = ysRDndYhHqiivjct()
    private override init() {}
    
    override func FNZyMHvCuqpTdvHZ(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String
    ) {
        if uwnLgFlhpyfCLJAx == .ChatRoom {
            return
        }
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() { return }
        let FnjJgXBhRPgnwHGk = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.CZJecwYjjXBOhITh(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            switch uwnLgFlhpyfCLJAx {
            case .P2P:
                ((_YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!) && (_YIMTable_Message.to == IYfxgmQIzqRJWEUV))
                || ((_YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!) && (_YIMTable_Message.from == IYfxgmQIzqRJWEUV))
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            case .Team:
                _YIMTable_Message.to == IYfxgmQIzqRJWEUV && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            default:
                _YIMTable_Message.t_id.isNil()
            }
        }, XDbstgapvwDPECiX: _YIMTable_Message.__)
        if !FnjJgXBhRPgnwHGk { return }
        fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.CZJecwYjjXBOhITh(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV)
    }
    
    override func MbucNQbvGvlflxEY(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        lnPbkmdwNECDwBnh: ((_ mKUIzAxlvBGUVfVk: Bool) throws -> Void)? = nil
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(false)
            }
            return
        }
        NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "clearServerHistory", EeqbYNIBaZfkqYaF: [
            "conversationType" : uwnLgFlhpyfCLJAx.rawValue,
            "conversationID" : IYfxgmQIzqRJWEUV,
        ]) { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
            if !mKUIzAxlvBGUVfVk {
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? lnPbkmdwNECDwBnh?(false)
                }
                return
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(true)
            }
        }
    }
    
    override func mSoMkADrXnBLbDrX(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        IMuPBNSVQxljIWnu: String,
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .Text,
            content: IMuPBNSVQxljIWnu,
            push: bgaUTCffvgrJbXZU,
            callback_start: rDanffAecmNObeZc,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    override func SZkDSZugPVtsKZXR(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        amwLsSsqearISEaM: String,
        oAsyNaycKGRQxdey: Int,
        JOQHofjVVgsKutMD: Int? = nil, //仅filePath为网络url时需要
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        wUCaANiqdIPstrIA: ((_ message: YIMMessage, _ count: Int, _ total: Int) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        let WPtiVrIseZORQmMJ = YIMAttachmentExt_Audio()
        WPtiVrIseZORQmMJ.duration = oAsyNaycKGRQxdey
        let VwZPoNqlsEbReUxE = YIMAttachment()
        VwZPoNqlsEbReUxE.type = .Audio
        VwZPoNqlsEbReUxE.url = amwLsSsqearISEaM
        VwZPoNqlsEbReUxE.size = JOQHofjVVgsKutMD ?? NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.oGyUzfiicTuvfkwc(VuFCApXqAiuIKaUF: amwLsSsqearISEaM)
        VwZPoNqlsEbReUxE.format = amwLsSsqearISEaM.components(separatedBy: ".").last!
        VwZPoNqlsEbReUxE.ext = WPtiVrIseZORQmMJ
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .Audio,
            attachment: VwZPoNqlsEbReUxE,
            push: bgaUTCffvgrJbXZU,
            callback_start: rDanffAecmNObeZc,
            callback_upload: wUCaANiqdIPstrIA,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    override func zlbjOfyLJVjfEFMd(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        amwLsSsqearISEaM: String,
        vCnvSnhevITORrOX: Bool = true,
        JOQHofjVVgsKutMD: Int? = nil, //仅filePath为网络url时需要
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        wUCaANiqdIPstrIA: ((_ message: YIMMessage, _ count: Int, _ total: Int) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        let WPtiVrIseZORQmMJ = YIMAttachmentExt_Image()
        WPtiVrIseZORQmMJ.compress = vCnvSnhevITORrOX
        let VwZPoNqlsEbReUxE = YIMAttachment()
        VwZPoNqlsEbReUxE.type = .Image
        VwZPoNqlsEbReUxE.url = amwLsSsqearISEaM
        VwZPoNqlsEbReUxE.size = JOQHofjVVgsKutMD ?? NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.oGyUzfiicTuvfkwc(VuFCApXqAiuIKaUF: amwLsSsqearISEaM)
        VwZPoNqlsEbReUxE.format = amwLsSsqearISEaM.components(separatedBy: ".").last!
        VwZPoNqlsEbReUxE.ext = WPtiVrIseZORQmMJ
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .Image,
            attachment: VwZPoNqlsEbReUxE,
            push: bgaUTCffvgrJbXZU,
            callback_start: rDanffAecmNObeZc,
            callback_upload: wUCaANiqdIPstrIA,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    override func ModzpLRaSeSkFIqn(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        amwLsSsqearISEaM: String,
        vCnvSnhevITORrOX: Bool = true,
        oAsyNaycKGRQxdey: Int,
        JOQHofjVVgsKutMD: Int? = nil, //仅filePath为网络url时需要
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        wUCaANiqdIPstrIA: ((_ message: YIMMessage, _ count: Int, _ total: Int) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        let WPtiVrIseZORQmMJ = YIMAttachmentExt_Video()
        WPtiVrIseZORQmMJ.compress = vCnvSnhevITORrOX
        WPtiVrIseZORQmMJ.image = NbDnvbpESqnqDInl.vCnvSnhevITORrOX.DDEhzNuCVDuCATRh(amwLsSsqearISEaM: amwLsSsqearISEaM)
        WPtiVrIseZORQmMJ.duration = oAsyNaycKGRQxdey
        let VwZPoNqlsEbReUxE = YIMAttachment()
        VwZPoNqlsEbReUxE.type = .Video
        VwZPoNqlsEbReUxE.url = amwLsSsqearISEaM
        VwZPoNqlsEbReUxE.size = JOQHofjVVgsKutMD ?? NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.oGyUzfiicTuvfkwc(VuFCApXqAiuIKaUF: amwLsSsqearISEaM)
        VwZPoNqlsEbReUxE.format = amwLsSsqearISEaM.components(separatedBy: ".").last!
        VwZPoNqlsEbReUxE.ext = WPtiVrIseZORQmMJ
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .Video,
            attachment: VwZPoNqlsEbReUxE,
            push: bgaUTCffvgrJbXZU,
            callback_start: rDanffAecmNObeZc,
            callback_upload: wUCaANiqdIPstrIA,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    override func RHxqHfXCmeMsPHsO(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        amwLsSsqearISEaM: String,
        MrlopvTAvrOKZfYM: String,
        JOQHofjVVgsKutMD: Int? = nil, //仅filePath为网络url时需要
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        wUCaANiqdIPstrIA: ((_ message: YIMMessage, _ count: Int, _ total: Int) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        let WPtiVrIseZORQmMJ = YIMAttachmentExt_File()
        WPtiVrIseZORQmMJ.name = MrlopvTAvrOKZfYM
        let VwZPoNqlsEbReUxE = YIMAttachment()
        VwZPoNqlsEbReUxE.type = .File
        VwZPoNqlsEbReUxE.url = amwLsSsqearISEaM
        VwZPoNqlsEbReUxE.size = JOQHofjVVgsKutMD ?? NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.oGyUzfiicTuvfkwc(VuFCApXqAiuIKaUF: amwLsSsqearISEaM)
        VwZPoNqlsEbReUxE.format = amwLsSsqearISEaM.components(separatedBy: ".").last!
        VwZPoNqlsEbReUxE.ext = WPtiVrIseZORQmMJ
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .File,
            attachment: VwZPoNqlsEbReUxE,
            push: bgaUTCffvgrJbXZU,
            callback_start: rDanffAecmNObeZc,
            callback_upload: wUCaANiqdIPstrIA,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    override func nmslEzaZUNEtGLhe(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        IMuPBNSVQxljIWnu: String,
        bgaUTCffvgrJbXZU: YIMPushOption? = nil,
        ytfJVFJHkAGqLytt: Bool = false,
        rDanffAecmNObeZc: ((_ message: YIMMessage) throws -> Void)? = nil,
        hzmQVkPAMRjQTTUo: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        dTnjljZuDIzEIQvm(
            conversationType: uwnLgFlhpyfCLJAx,
            conversationID: IYfxgmQIzqRJWEUV,
            messageType: .Custom,
            content: IMuPBNSVQxljIWnu,
            push: bgaUTCffvgrJbXZU,
            onlyInsert: ytfJVFJHkAGqLytt,
            callback_start: rDanffAecmNObeZc,
            callback_finish: hzmQVkPAMRjQTTUo
        )
    }
    
    internal override func dTnjljZuDIzEIQvm(
        conversationType: YIMEnum_ConversationType,
        conversationID: String,
        messageType: YIMEnum_MessageType,
        content: String? = nil,
        attachment: YIMAttachment? = nil,
        push: YIMPushOption? = nil,
        onlyInsert: Bool = false,
        callback_start: ((_ message: YIMMessage) throws -> Void)? = nil,
        callback_upload: ((_ message: YIMMessage, _ count: Int, _ total: Int) throws -> Void)? = nil,
        callback_finish: ((_ isSuccess: Bool, _ message: YIMMessage, _ code: Int, _ msg: String) throws -> Void)? = nil
    ) {
        func DqTrbCPrZklGcRHY(UoYOCIDnMCtSoXZx: YIMInfo?) {
            let GZRevkeIIdHLwXxe = YIMMessage()
            GZRevkeIIdHLwXxe.conversationType = conversationType
            GZRevkeIIdHLwXxe.messageType = messageType
            GZRevkeIIdHLwXxe.content = content
            GZRevkeIIdHLwXxe.attachment = attachment
            GZRevkeIIdHLwXxe.messageState = .Sending
            GZRevkeIIdHLwXxe.from = NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!
            GZRevkeIIdHLwXxe.fromInfo = NbDnvbpESqnqDInl.ZPyrCbzOlbdctqkw
            GZRevkeIIdHLwXxe.to = conversationID
            if UoYOCIDnMCtSoXZx == nil {
                let UoYOCIDnMCtSoXZx = YIMInfo()
                UoYOCIDnMCtSoXZx.id = conversationID
                GZRevkeIIdHLwXxe.toInfo = UoYOCIDnMCtSoXZx
            } else {
                GZRevkeIIdHLwXxe.toInfo = UoYOCIDnMCtSoXZx
            }
            GZRevkeIIdHLwXxe.time = Int(Date().timeIntervalSince1970 * 1000)
            switch conversationType {
            case .P2P:
                GZRevkeIIdHLwXxe.id = "message_p2p_\(ULID().ulidString)"
            case .Team:
                GZRevkeIIdHLwXxe.id = "message_team_\(ULID().ulidString)"
            case .ChatRoom:
                GZRevkeIIdHLwXxe.id = "message_room_\(ULID().ulidString)"
            default:
                GZRevkeIIdHLwXxe.id = ""
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? callback_start?(GZRevkeIIdHLwXxe)
            }
            if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
                GZRevkeIIdHLwXxe.messageState = .Fail
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "Please login first")
                }
                return
            }
            if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(GZRevkeIIdHLwXxe.conversationType) {
                let xjSWySxclwWCwOiY = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.KamiWNsKhqtzmVUX(_YIMTable_Message.self, EeqbYNIBaZfkqYaF: _YIMTable_Message(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe))
                if !xjSWySxclwWCwOiY {
                    GZRevkeIIdHLwXxe.messageState = .Fail
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "insert msg error")
                    }
                    return
                }
                let pLPuPjymILJmMTHC = {
                    switch conversationType {
                    case YIMEnum_ConversationType.P2P:
                        ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == conversationID)
                         || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == conversationID))
                        && (_YIMTable_Conversation._conversationType == conversationType.rawValue)
                    case YIMEnum_ConversationType.Team:
                        _YIMTable_Conversation._to == conversationID
                        && _YIMTable_Conversation._conversationType == conversationType.rawValue
                    default:
                        _YIMTable_Conversation.t_id.isNil()
                    }
                }
                var ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    GZRevkeIIdHLwXxe.messageState = .Fail
                    enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "query old conversation error")
                    }
                    return
                }
                let ZMbwDIvEfxQvwQMb = ufiMwtSGkwkOKTnp!.isEmpty
                // 创建或修改会话最后一条消息
                GZRevkeIIdHLwXxe.messageState = .Success_UnRead
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(        uwnLgFlhpyfCLJAx: conversationType,         IYfxgmQIzqRJWEUV: conversationID)
                if !drotiWAFkowcWbqO {
                    GZRevkeIIdHLwXxe.messageState = .Fail
                    enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "update conversation1 error")
                    }
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    GZRevkeIIdHLwXxe.messageState = .Fail
                    enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "query new conversation error1")
                    }
                    return
                }
                if ZMbwDIvEfxQvwQMb {
                    //新增的会话
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.SStXrjMtBhxsVxWV?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                    }
                } else {
                    //原有的会话
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                    }
                }
            }
            if content != nil && content!.count > 4096 {
                GZRevkeIIdHLwXxe.messageState = .Fail
                enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "content size over than 4096")
                }
                return
            }
            
            if onlyInsert { return }
            
            func cLduREKJPaOgOzuY() {
                NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "sendMessage", EeqbYNIBaZfkqYaF: [
                    "message": NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV(GZRevkeIIdHLwXxe),
                    "push": push == nil ? nil : NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV(push!),
                ]) { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
                    if mKUIzAxlvBGUVfVk {
                        GZRevkeIIdHLwXxe.messageState = .Success_UnRead
                        GZRevkeIIdHLwXxe.time = Int("\(EyTIVrNCTVqmYwPu!["time"]!)")!
                        GZRevkeIIdHLwXxe.toInfo = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EyTIVrNCTVqmYwPu!["toInfo"], YIMInfo.self)
                    } else {
                        GZRevkeIIdHLwXxe.messageState = .Fail
                    }
                    // 更新新消息发送状态
                    self.enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? callback_finish?(mKUIzAxlvBGUVfVk, GZRevkeIIdHLwXxe, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP)
                    }
                }
            }
            
            if GZRevkeIIdHLwXxe.attachment?.url != nil {
                func kDfxkBtFUkZRElku(xNQEJdBlJmPlsLZJ: ((_ nYmOYAxJcugyWBBX: String, _ fsqireLWzjUHlOsI: @escaping (_ VuFCApXqAiuIKaUF: String) -> Void) -> Void)? = nil, fsqireLWzjUHlOsI: @escaping () -> Void) {
                    if GZRevkeIIdHLwXxe.attachment!.url.starts(with: "http://") || GZRevkeIIdHLwXxe.attachment!.url.starts(with: "https://") {
                        fsqireLWzjUHlOsI()
                        return
                    }
                    
                    func wNssuYBZMLNzzzMK() {
                        NbDnvbpESqnqDInl.hUaxJkdEfQCZrrHT.kDfxkBtFUkZRElku(
                            amwLsSsqearISEaM: GZRevkeIIdHLwXxe.attachment!.url,
                            yGxCIvPKkYdnsEub: "\(NbDnvbpESqnqDInl.HNMTEjFdjzjxYWYx!.appKey!)/\(NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!)/\(String(describing: messageType))"
                        ) { hyridvHtGRONajzD, rzZhbifyokYykTwb in
                            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                try? callback_upload?(GZRevkeIIdHLwXxe, hyridvHtGRONajzD, rzZhbifyokYykTwb)
                            }
                        } WlyMgrlTDrLWiMcu: { mKUIzAxlvBGUVfVk, nYmOYAxJcugyWBBX, QWgDujAUvfAGYENs in
                            if !mKUIzAxlvBGUVfVk {
                                GZRevkeIIdHLwXxe.messageState = .Fail
                                self.enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                    try? callback_finish?(false, GZRevkeIIdHLwXxe, 0, "file upload error:\(QWgDujAUvfAGYENs!)")
                                }
                                return
                            }
                            GZRevkeIIdHLwXxe.attachment!.url = nYmOYAxJcugyWBBX!
                            self.enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                            fsqireLWzjUHlOsI()
                        }
                    }
                    
                    if xNQEJdBlJmPlsLZJ != nil {
                        xNQEJdBlJmPlsLZJ!(GZRevkeIIdHLwXxe.attachment!.url) { VuFCApXqAiuIKaUF in
                            GZRevkeIIdHLwXxe.attachment!.url = VuFCApXqAiuIKaUF
                            GZRevkeIIdHLwXxe.attachment!.size = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.oGyUzfiicTuvfkwc(VuFCApXqAiuIKaUF: VuFCApXqAiuIKaUF)
                            self.enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                            wNssuYBZMLNzzzMK()
                        }
                    } else {
                        wNssuYBZMLNzzzMK()
                    }
                }
                
                switch messageType {
                case .Audio:
                    kDfxkBtFUkZRElku { cLduREKJPaOgOzuY() }
                case .Image:
                    let WPtiVrIseZORQmMJ = GZRevkeIIdHLwXxe.attachment!.ext as! YIMAttachmentExt_Image
                    if WPtiVrIseZORQmMJ.compress {
                        kDfxkBtFUkZRElku { nYmOYAxJcugyWBBX, fsqireLWzjUHlOsI in
                            NbDnvbpESqnqDInl.vCnvSnhevITORrOX.tKOBXqnxiKXdGeAJ(wIgXmVpmRMRncLHs: nYmOYAxJcugyWBBX) { fsqireLWzjUHlOsI($0!) }
                        } fsqireLWzjUHlOsI: {
                            cLduREKJPaOgOzuY()
                        }
                    } else {
                        kDfxkBtFUkZRElku { cLduREKJPaOgOzuY() }
                    }
                case .Video:
                    let WPtiVrIseZORQmMJ = GZRevkeIIdHLwXxe.attachment!.ext as! YIMAttachmentExt_Video
                    if WPtiVrIseZORQmMJ.compress {
                        kDfxkBtFUkZRElku { nYmOYAxJcugyWBBX, fsqireLWzjUHlOsI in
                            NbDnvbpESqnqDInl.vCnvSnhevITORrOX.bzetInzTlZDFtLvT(GGXyiTtwzKqMgeya: nYmOYAxJcugyWBBX) { fsqireLWzjUHlOsI($0!) }
                        } fsqireLWzjUHlOsI: {
                            WPtiVrIseZORQmMJ.image = NbDnvbpESqnqDInl.hUaxJkdEfQCZrrHT.GOyxLapaPKzDshmz(BrunOZpLCJfGfiVp: GZRevkeIIdHLwXxe.attachment!.url)
                            self.enzTDObZcftkhSRl(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                            cLduREKJPaOgOzuY()
                        }
                    } else {
                        kDfxkBtFUkZRElku { cLduREKJPaOgOzuY() }
                    }
                case .File:
                    kDfxkBtFUkZRElku { cLduREKJPaOgOzuY() }
                default: break
                }
            } else {
                cLduREKJPaOgOzuY()
            }
        }
        
        fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
            let hfpHDswgBZxdzWjN = ormchpikGcmflTHU?.first { $0.getConversationID() == conversationID }
            if hfpHDswgBZxdzWjN != nil {
                switch hfpHDswgBZxdzWjN!.lastMessage.conversationType {
                case .P2P:
                    if (hfpHDswgBZxdzWjN!.getIsMine()) {
                        DqTrbCPrZklGcRHY(UoYOCIDnMCtSoXZx: hfpHDswgBZxdzWjN!.lastMessage.toInfo)
                    } else {
                        DqTrbCPrZklGcRHY(UoYOCIDnMCtSoXZx: hfpHDswgBZxdzWjN!.lastMessage.fromInfo)
                    }
                default:
                    DqTrbCPrZklGcRHY(UoYOCIDnMCtSoXZx: hfpHDswgBZxdzWjN!.lastMessage.toInfo)
                }
            } else {
                DqTrbCPrZklGcRHY(UoYOCIDnMCtSoXZx: nil)
            }
        }
    }
    
    override func zBerOKEdTNDPVNug(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        cWSIMxBBOoVwGhZm: String
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() { return }
        DqByaaGxdiZfiqiE(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV, jVYApcVixeqcbOqW: [cWSIMxBBOoVwGhZm])
    }
    
    override func DqByaaGxdiZfiqiE(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        jVYApcVixeqcbOqW: [String]
    ) {
        if uwnLgFlhpyfCLJAx == .ChatRoom {
            return
        }
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() { return }
        let FnjJgXBhRPgnwHGk = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.CZJecwYjjXBOhITh(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            switch uwnLgFlhpyfCLJAx {
            case YIMEnum_ConversationType.P2P:
                ((_YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                 || (_YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.from == IYfxgmQIzqRJWEUV))
                && (_YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue)
                && _YIMTable_Message.id.isIn(jVYApcVixeqcbOqW)
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            case YIMEnum_ConversationType.Team:
                (_YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                && (_YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue)
                && _YIMTable_Message.id.isIn(jVYApcVixeqcbOqW)
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            default:
                _YIMTable_Message.t_id.isNil()
            }
        }, XDbstgapvwDPECiX: _YIMTable_Message.__)
        if !FnjJgXBhRPgnwHGk { return }
        let hyridvHtGRONajzD = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.hyridvHtGRONajzD(_YIMTable_Message.self) {
            switch uwnLgFlhpyfCLJAx {
            case YIMEnum_ConversationType.P2P:
                ((_YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                 || (_YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.from == IYfxgmQIzqRJWEUV))
                && (_YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue)
            case YIMEnum_ConversationType.Team:
                (_YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                && (_YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue)
            default:
                _YIMTable_Message.t_id.isNil()
            }
        }
        if hyridvHtGRONajzD == nil { return }
        if hyridvHtGRONajzD! > 0 {
            let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(        uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx,         IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV,         QfmrhidBvfBIkVBE: .ZTxjOcgnwyCfNSIz)
            if !drotiWAFkowcWbqO { return }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
            }
            let pLPuPjymILJmMTHC = {
                switch uwnLgFlhpyfCLJAx {
                case YIMEnum_ConversationType.P2P:
                    ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV)
                     || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == IYfxgmQIzqRJWEUV))
                    && (_YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue)
                case YIMEnum_ConversationType.Team:
                    _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV
                    && _YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue
                default:
                    _YIMTable_Conversation.t_id.isNil()
                }
            }
            let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                _YIMTable_Conversation.self,
                gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                XDbstgapvwDPECiX: _YIMTable_Conversation._time
            )
            if ufiMwtSGkwkOKTnp == nil {
                return
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
            }
        } else {
            fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.CZJecwYjjXBOhITh(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV)
        }
    }
    
    override func shshcyxYSnepQxBy(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        NhoLjQazYHvziqpY: Date? = nil,
        qNVQZENZAHSIHdwn: Bool = false,
        KLywTOzhcQSiFAmi: Int = 20,
        EzGrRSSYXvaXYSEV: YIMEnum_QueryDirection = .Old,
        lnPbkmdwNECDwBnh: @escaping ((_ zpAppbgYcokukiGf: [YIMMessage]?) throws -> Void)
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(nil)
            }
            return
        }
        if uwnLgFlhpyfCLJAx == .ChatRoom {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh([])
            }
            return
        }
        let KLywTOzhcQSiFAmi = KLywTOzhcQSiFAmi > 100 ? 100 : KLywTOzhcQSiFAmi
        let EyTIVrNCTVqmYwPu = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            switch uwnLgFlhpyfCLJAx {
            case .P2P:
                (NhoLjQazYHvziqpY == nil
                 ? _YIMTable_Message.time.isNotNil()
                 : (EzGrRSSYXvaXYSEV == .Old
                    ? _YIMTable_Message.time < Int(NhoLjQazYHvziqpY!.timeIntervalSince1970 * 1000)
                    : _YIMTable_Message.time > Int(NhoLjQazYHvziqpY!.timeIntervalSince1970 * 1000)))
                &&
                (qNVQZENZAHSIHdwn
                 ? _YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV
                 : (_YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV) || _YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.from == IYfxgmQIzqRJWEUV)
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            case .Team:
                (NhoLjQazYHvziqpY == nil
                 ? _YIMTable_Message.time.isNotNil()
                 : (EzGrRSSYXvaXYSEV == .Old
                    ? _YIMTable_Message.time < Int(NhoLjQazYHvziqpY!.timeIntervalSince1970 * 1000)
                    : _YIMTable_Message.time > Int(NhoLjQazYHvziqpY!.timeIntervalSince1970 * 1000)))
                &&
                (qNVQZENZAHSIHdwn
                 ? _YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV
                 : _YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            default:
                _YIMTable_Message.t_id.isNil()
            }
        }, XDbstgapvwDPECiX: _YIMTable_Message.time, XnhSWuJgBTGuusap: false, KLywTOzhcQSiFAmi: KLywTOzhcQSiFAmi)
        if EyTIVrNCTVqmYwPu == nil {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(nil)
            }
            return
        }
        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
            try? lnPbkmdwNECDwBnh(EyTIVrNCTVqmYwPu!.reversed().map{ YIMMessage(GZRevkeIIdHLwXxe: $0) })
        }
    }
    
    override func FMCEiTfVplJHuoRQ(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        NhoLjQazYHvziqpY: Int? = nil,
        KLywTOzhcQSiFAmi: Int = 20,
        EzGrRSSYXvaXYSEV: YIMEnum_QueryDirection = .Old,
        lnPbkmdwNECDwBnh: @escaping ((_ mKUIzAxlvBGUVfVk: Bool, _ messages: [YIMMessage]?) throws -> Void)
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(false, nil)
            }
            return
        }
        NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "queryMessages", EeqbYNIBaZfkqYaF: [
            "conversationType" : uwnLgFlhpyfCLJAx.rawValue,
            "conversationID" : IYfxgmQIzqRJWEUV,
            "time" : NhoLjQazYHvziqpY ?? Int(Date().timeIntervalSince1970 * 1000),
            "limit" : KLywTOzhcQSiFAmi,
            "queryDirection" : EzGrRSSYXvaXYSEV.rawValue,
        ]) { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
            if !mKUIzAxlvBGUVfVk {
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? lnPbkmdwNECDwBnh(false, nil)
                }
                return
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(true, NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EyTIVrNCTVqmYwPu!["messages"], [_YIMTable_Message].self)?.map({ GZRevkeIIdHLwXxe in
                    YIMMessage(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe)
                }))
            }
        }
    }
    
    override func UDlAPdNiKaWWGSod(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        cWSIMxBBOoVwGhZm: String,
        lnPbkmdwNECDwBnh: @escaping ((_ GZRevkeIIdHLwXxe: YIMMessage?) throws -> Void)
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(nil)
            }
            return
        }
        TABxswoOHTGZgVxu(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV, jVYApcVixeqcbOqW: [cWSIMxBBOoVwGhZm]) { zpAppbgYcokukiGf in
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(zpAppbgYcokukiGf == nil || zpAppbgYcokukiGf!.isEmpty ? nil : zpAppbgYcokukiGf!.first)
            }
        }
    }
    
    override func TABxswoOHTGZgVxu(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        jVYApcVixeqcbOqW: [String],
        lnPbkmdwNECDwBnh: @escaping ((_ zpAppbgYcokukiGf: [YIMMessage]?) throws -> Void)
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(nil)
            }
            return
        }
        let EyTIVrNCTVqmYwPu = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            _YIMTable_Message.id.isIn(jVYApcVixeqcbOqW)
        }, XDbstgapvwDPECiX: _YIMTable_Message.time, XnhSWuJgBTGuusap: true)
        if EyTIVrNCTVqmYwPu == nil {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh(nil)
            }
            return
        }
        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
            try? lnPbkmdwNECDwBnh(EyTIVrNCTVqmYwPu!.map{ YIMMessage(GZRevkeIIdHLwXxe: $0) })
        }
    }
    
    override func enzTDObZcftkhSRl(
        GZRevkeIIdHLwXxe: YIMMessage
    ) {
        if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(GZRevkeIIdHLwXxe.conversationType) {
            if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() { return }
            let _ = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
                _YIMTable_Message.id == GZRevkeIIdHLwXxe.id
            }, tuATquJzrMWXRcKf: {
                $0?.first?.update(GZRevkeIIdHLwXxe: _YIMTable_Message(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe))
                return $0
            }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
                EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
            }, XDbstgapvwDPECiX: _YIMTable_Message.__)
            let _ = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(        uwnLgFlhpyfCLJAx: GZRevkeIIdHLwXxe.conversationType,         IYfxgmQIzqRJWEUV: GZRevkeIIdHLwXxe.getConversationID(),         QfmrhidBvfBIkVBE: .ZTxjOcgnwyCfNSIz)
            let pLPuPjymILJmMTHC = {
                switch GZRevkeIIdHLwXxe.conversationType! {
                case YIMEnum_ConversationType.P2P:
                    ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == GZRevkeIIdHLwXxe.getConversationID())
                     || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == GZRevkeIIdHLwXxe.getConversationID()))
                    && (_YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue)
                case YIMEnum_ConversationType.Team:
                    _YIMTable_Conversation._to == GZRevkeIIdHLwXxe.getConversationID()
                    && _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                case YIMEnum_ConversationType.ChatRoom:
                    _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                default:
                    _YIMTable_Conversation.t_id.isNil()
                }
            }
            let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                _YIMTable_Conversation.self,
                gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                XDbstgapvwDPECiX: _YIMTable_Conversation._time
            )
            if ufiMwtSGkwkOKTnp == nil {
                return
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
            }
        }
    }
    
    override func GNBnhDyxzJEkLvXc(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        lnPbkmdwNECDwBnh: ((_ mKUIzAxlvBGUVfVk: Bool) throws -> Void)? = nil
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(false)
            }
            return
        }
        NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "sendMessageReceipt", EeqbYNIBaZfkqYaF: [
            "conversationType" : uwnLgFlhpyfCLJAx.rawValue,
            "conversationID" : IYfxgmQIzqRJWEUV,
        ]) { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
            if !mKUIzAxlvBGUVfVk {
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? lnPbkmdwNECDwBnh?(false)
                }
                return
            }
            if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(uwnLgFlhpyfCLJAx) {
                let AvHYKzLJAAoKcnSR = self.SwjLZskphOFqktRN(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV, IyFwCVRgYzNeLHkj: true)
                if !AvHYKzLJAAoKcnSR {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? lnPbkmdwNECDwBnh?(false)
                    }
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                let pLPuPjymILJmMTHC = {
                    switch uwnLgFlhpyfCLJAx {
                    case YIMEnum_ConversationType.P2P:
                        ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV)
                         || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == IYfxgmQIzqRJWEUV))
                        && (_YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue)
                    case YIMEnum_ConversationType.Team:
                        _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV
                        && _YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue
                    default:
                        _YIMTable_Conversation.t_id.isNil()
                    }
                }
                let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                }
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(true)
            }
        }
    }
    
    override func JWwYEELfRlMAzSWC(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        cWSIMxBBOoVwGhZm: String,
        lnPbkmdwNECDwBnh: ((_ mKUIzAxlvBGUVfVk: Bool) throws -> Void)? = nil
    ) {
        if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(false)
            }
            return
        }
        NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "sendMessageRevoke", EeqbYNIBaZfkqYaF: [
            "conversationType" : uwnLgFlhpyfCLJAx.rawValue,
            "conversationID" : IYfxgmQIzqRJWEUV,
            "messageID" : cWSIMxBBOoVwGhZm,
        ]) { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
            if !mKUIzAxlvBGUVfVk {
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? lnPbkmdwNECDwBnh?(false)
                }
                return
            }
            if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(uwnLgFlhpyfCLJAx) {
                let mutHbqGGkcrRPdCJ = self.isgJTwrjAjJefSGB(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, cWSIMxBBOoVwGhZm: cWSIMxBBOoVwGhZm)
                if !mutHbqGGkcrRPdCJ {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? lnPbkmdwNECDwBnh?(false)
                    }
                    return
                }
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(uwnLgFlhpyfCLJAx: uwnLgFlhpyfCLJAx, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV)
                if !drotiWAFkowcWbqO {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? lnPbkmdwNECDwBnh?(false)
                    }
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                let pLPuPjymILJmMTHC = {
                    switch uwnLgFlhpyfCLJAx {
                    case YIMEnum_ConversationType.P2P:
                        ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV)
                         || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == IYfxgmQIzqRJWEUV))
                        && (_YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue)
                    case YIMEnum_ConversationType.Team:
                        _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV
                        && _YIMTable_Conversation._conversationType == uwnLgFlhpyfCLJAx.rawValue
                    default:
                        _YIMTable_Conversation.t_id.isNil()
                    }
                }
                let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                }
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(true)
            }
        }
    }
    
    internal override func SwjLZskphOFqktRN(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        IYfxgmQIzqRJWEUV: String,
        IyFwCVRgYzNeLHkj: Bool
    ) -> Bool {
        let EyTIVrNCTVqmYwPu = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            _YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!
            && _YIMTable_Message.to == IYfxgmQIzqRJWEUV
            && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
        }, XDbstgapvwDPECiX: _YIMTable_Message.time, XnhSWuJgBTGuusap: false, KLywTOzhcQSiFAmi: 1)
        if EyTIVrNCTVqmYwPu == nil || EyTIVrNCTVqmYwPu!.isEmpty { return false }
        if EyTIVrNCTVqmYwPu!.first!.messageState == YIMEnum_MessageState.Success_Read.rawValue { return false }
        switch uwnLgFlhpyfCLJAx {
        case .P2P:
            let mXlTEoCuvqhGCSmB = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
                (IyFwCVRgYzNeLHkj
                         ? (_YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.from == IYfxgmQIzqRJWEUV)
                         : (_YIMTable_Message.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.to == IYfxgmQIzqRJWEUV) || (_YIMTable_Message.to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Message.from == IYfxgmQIzqRJWEUV)
                ) && _YIMTable_Message.messageState == YIMEnum_MessageState.Success_UnRead.rawValue
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            }, tuATquJzrMWXRcKf: {
                $0?.forEach { $0.messageState = YIMEnum_MessageState.Success_Read.rawValue }
                return $0
            }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
                EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
            }, XDbstgapvwDPECiX: _YIMTable_Message.__)
            if !mXlTEoCuvqhGCSmB { return false }
        case .Team:
            let mXlTEoCuvqhGCSmB = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
                (IyFwCVRgYzNeLHkj
                         ? (_YIMTable_Message.to == IYfxgmQIzqRJWEUV && _YIMTable_Message.from != NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!)
                         : (_YIMTable_Message.to == IYfxgmQIzqRJWEUV)
                ) && _YIMTable_Message.messageState == YIMEnum_MessageState.Success_UnRead.rawValue
                && _YIMTable_Message.conversationType == uwnLgFlhpyfCLJAx.rawValue
            }, tuATquJzrMWXRcKf: {
                $0?.forEach { $0.messageState = YIMEnum_MessageState.Success_Read.rawValue }
                return $0
            }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
                EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
            }, XDbstgapvwDPECiX: _YIMTable_Message.__)
            if !mXlTEoCuvqhGCSmB { return false }
        case .ChatRoom:
            return true
        default:
            break
        }
        return true
    }
    
    internal override func isgJTwrjAjJefSGB(
        uwnLgFlhpyfCLJAx: YIMEnum_ConversationType,
        cWSIMxBBOoVwGhZm: String
    )  -> Bool  {
        let EyTIVrNCTVqmYwPu = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            _YIMTable_Message.id == cWSIMxBBOoVwGhZm
        }, XDbstgapvwDPECiX: _YIMTable_Message.time, XnhSWuJgBTGuusap: true)
        if EyTIVrNCTVqmYwPu == nil || EyTIVrNCTVqmYwPu!.isEmpty { return false }
        if EyTIVrNCTVqmYwPu!.first!.isRevoke == "1" { return false }
        let mXlTEoCuvqhGCSmB = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
            _YIMTable_Message.id == cWSIMxBBOoVwGhZm
        }, tuATquJzrMWXRcKf: {
            $0?.forEach { $0.isRevoke = "1" }
            return $0
        }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
            EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
        }, XDbstgapvwDPECiX: _YIMTable_Message.__)
        if !mXlTEoCuvqhGCSmB { return false }
        return true
    }
}
